import random
from google.appengine.ext import db
from google.appengine.ext import webapp
from flag_quiz import cia_factbook_url

class Flag(db.Model):
    img_url = db.StringProperty(required=True)
    code = db.StringProperty(required=True)
    name = db.StringProperty(required=True)

class FlagQuiz(webapp.RequestHandler):
    def get(self):
        query = Flag.all()
        text = ''
        try:
            for s in random.sample([q for q in query], 6):
                text += '%s <img src="%s%s">' %(s.name, cia_factbook_url, s.img_url[3:])
        except:
            text = 'oops no data'
        self.response.out.write(text)
